package tester.outcome.group;

import state.group.events.BaseEvent;
import state.group.events.DeregistrationEvent;
import state.group.events.EventCollection;
import state.group.events.EventType;
import tester.outcome.BaseEventOutcome;
import messages.observer.EventCollectionMessage;

/**
 * This method will check for deregistration event message for a given elevator
 * @author Caleb Chan
 *
 */
public class DeregistrationEventOutcome extends BaseEventOutcome {

	private byte elevatorId;
	
	/**
	 * DeregistrationEventOutcome constructor
	 * @param startTime The start time of the outcome
	 * @param elevatorId The elevator that has deregistered
	 */
	public DeregistrationEventOutcome(long startTime, byte elevatorId){
		super(startTime);
		this.elevatorId = elevatorId;
	}
	
	@Override
	public boolean checkOutcome(EventCollectionMessage message) {
		
		EventCollection collection = message.getEvents();
		
		for(BaseEvent e : collection){
			// Check if there is a Deregistration event 
			if (e.getEventType() == EventType.DeregistrationEvent){
				DeregistrationEvent rE = (DeregistrationEvent)e;
				// Checks if the elevator Id are correct
				if (rE.getElevatorId() == elevatorId){
					isCompleted = true;
				}
			}
		}
		
		return isCompleted;
	}

	@Override
	public String getOutcomeName() {
		return "DeregistrationEventOutcome";
	}

	@Override
	public BaseEventOutcome copy() {
		return new DeregistrationEventOutcome(0, elevatorId);
	}

	@Override
	public String getOutcomeChecksStr() {
		return getOutcomeName() + "Elevator -> " + elevatorId;
	}

}
